/*
Date:20210528 16:17PM
key:搞个哨兵节点，每次新链表的next不用new的，直接选合适的那一条连接上即可。
 */
class Solution {
public:
    ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) 
    {
        if(l1==NULL){return l2;}
        if(l2==NULL){return l1;}

        ListNode* shaobing=new ListNode;
        ListNode* head=shaobing;
        
        while(l1!=NULL&&l2!=NULL)
        {
            //shaobing->next=new ListNode;
            if(l1->val<l2->val)
            {
                shaobing->next=l1;
                l1=l1->next;
            }
            else
            {
                shaobing->next=l2;
                l2=l2->next;
            }
            
            shaobing=shaobing->next;
        }
        if(l1!=NULL)
        {
            shaobing->next=l1;
        }
        if(l2!=NULL)
        {
            shaobing->next=l2;
        }
        return head->next;
    }
};